$(function () {
    //Cotent
    //导航栏全部内容展开折叠
    $(".S-nav .select").click(function () {
        $(".S-nav .selectBox").slideToggle()
    });

    //评论列表展开与折叠
    $(".description .shares .comment").click(function () {
        $(this).parents(".description").siblings(".comments").slideToggle();
    });

    //新建评论
    $(".commentList .attitude .comment").click(function () {
        $(this).parents(".detail").find(".opinion").slideToggle();
    });

    //一键返回
    var btn = document.querySelector(".backToTop a");
    window.onscroll = function () {
        var bodyScrollHeight = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
        //一键返回
        if (bodyScrollHeight >= 350) {
            btn.style.visibility = "visible";
            btn.style.position = "fixed";
            btn.style.bottom = "50px";
            btn.style.top = "auto";
            btn.style.transition = "all .5s";
        }else {
            btn.style.visibility = "hidden";
            btn.style.transition = "all .5s";
        }

        btn.onclick = function () {
            var pos = bodyScrollHeight;
            var speed = bodyScrollHeight / 50;

            var timer = setInterval(function () {
                pos -= speed;
                if (document.body.scrollTop) {
                    document.body.scrollTop = pos;
                } else {
                    document.documentElement.scrollTop = pos;
                }
                if (pos <= 0) {
                    clearInterval(timer)
                }
            }, 1);
        };
    };
    window.onscroll();

    //S-centerBox 导航切换
    $(".S-centerBox .S-nav .navItem").click(function () {
        var index = $(this).index();
        $(this).addClass("active").siblings().removeClass("active");
        $(".S-centerBox .box > div").eq(index).show().siblings().hide();
    });

    //点赞
    $(".showItem .description .thumbsUp").click(function () {
        $(this).toggleClass("active");
    });

    //评论区 点赞
    $(".showItem .comments .attitude .like").click(function () {
        $(this).find(".fa-heart").toggleClass("active");
    });

    //评论框获取光标 & 失去光标 事件
    $(".showItem .comments .myOpinion input").focus(function () {
        $(this).parent().addClass("focus");
    });
    $(".showItem .comments .myOpinion input").blur(function () {
        $(this).parent().removeClass("focus");
    });

    //发现 -- 全部关注
    $(".discovery .followAll").click(function () {
        $(".discovery .userList .item").addClass("followed");
    });

    //发现 -- 关注按钮
    $(".discovery .userList .item .follow").click(function () {
        $(this).parents(".item").toggleClass("followed");
        if($(this).parents(".item").hasClass("followed")) {
            $(this).html("<i class='fa fa-star'></i>已关注");
        }else{
            $(this).html("<i class='fa fa-star'></i>关注");
        }
    });

    window._bd_share_config = {
        common : {
            bdText : '自定义分享内容',
            bdDesc : '自定义分享摘要',
            bdUrl : '自定义分享url地址',
            bdPic : '自定义分享图片'
        },
        share : [{
            "bdSize" : 32
        }]
    };
    with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
});